//
//  PhotoBrowerCell.swift
//  MyWeibo
//
//  Created by 余丽丽 on 15/10/21.
//  Copyright © 2015年 余丽丽. All rights reserved.
//

import UIKit
import SDWebImage
class PhotoBrowerCell: UICollectionViewCell {
   
    var imgURL:NSURL?{
    
        didSet{
            indicator.startAnimating()
            photoImg.sd_setImageWithURL(self.imgURL){(image,_,_,_) in
            
                self.indicator.stopAnimating()
            
            }
        
        }
    }
    
    
   override init(frame: CGRect) {
        super.init(frame: frame)
        //设置UI
        setupUI()
        // 显示菊花
        indicator.startAnimating()
    
    }

    
   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
    
    
    private func setupUI(){
    
        //添加子控件
        contentView.addSubview(photoScrollView)
        contentView.addSubview(indicator)
        photoScrollView.addSubview(photoImg)
        
        //子控件布局
        indicator.center = photoScrollView.center
    
        //设置控件属性
        setupAttribute()
    }
    
    private func setupAttribute(){
    
        //图片缩放器的缩放比例
        photoScrollView.minimumZoomScale = 0.5
        photoScrollView.maximumZoomScale = 2
//        photoScrollView.backgroundColor = UIColor.randomColor()
        
    
    }
    
    // MARK: - 懒加载控件
     /// 图片缩放器
    private lazy var photoScrollView:UIScrollView = UIScrollView(frame: UIScreen.mainScreen().bounds)
    /// 图片
     lazy var photoImg:UIImageView = UIImageView(frame: UIScreen.mainScreen().bounds)
    /// 菊花
    private lazy var indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)
    
}
